//
//  GCMCBYIJIViewController.m
//  GeeCityManager
//
//  Created by 聚城科技 on 16/10/9.
//  Copyright © 2016年 聚城科技. All rights reserved.
//

#import "GCMCBYIJIViewController.h"
#import "GCMChaoBiaoViewController.h"
#import "GCMCBTJTableViewCell.h"

@interface GCMCBYIJIViewController ()<UITableViewDataSource, UITableViewDelegate,UIAlertViewDelegate>{
    
    NSMutableArray *_DataArray;
    NSMutableArray *_reciveXiaoquArray;
    UIButton * _leftbutton;
    UIButton * _rightbutton;
    UITableView *_tableView;
    NSString *_returnMsg;
    NSMutableArray *_yearArr;
    NSMutableArray *_monthArr;
    UITableView *_tableV;
    NSMutableArray *_dataSource;
    NSInteger _currentPage;
    NSString *_areaStr;
    
    
}


@end

@implementation GCMCBYIJIViewController{

    UIImageView *_uInfoView;
    UILabel *_cbrLab;
    UILabel *_timeLab;
    UILabel *_areaLab;
    UILabel *_Dyingchacount;
    UILabel *_Dyichacount;
    UILabel *_Dweichacount;
    UILabel *_Syingchacount;
    UILabel *_Syichacount;
    UILabel *_Sweichacount;
    
    
    
}

-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createUI];
    [self downLoadData];
    
    

}

-(void)downLoadData{

    [GCMHostSearchHttpRequst postDataWithUserName:[GCMUserInfo instance].realName Success:^(id obj, NSError *err) {
//        NSLog(@"小区%@",obj);
        _reciveXiaoquArray = [[NSMutableArray alloc]init];
        _areaStr = [[NSString alloc]init];
        NSArray *arr = [NSArray arrayWithArray:obj];
        for (NSDictionary *dic in arr) {
            [_reciveXiaoquArray addObject:[dic valueForKey:@"id"]];
        }
        _areaStr = [_reciveXiaoquArray componentsJoinedByString:@","];
//        NSLog( @"%@",_areaStr);
        _areaStr = [_reciveXiaoquArray componentsJoinedByString:@","];
        [GCMCBLRRequst postCBLRDataWithId:_areaStr Success:^(id obj, NSError *err) {
            _dataSource = obj;
//            NSLog(@"%@",_dataSource);
            [self createTableView];
        }];
    }];

    

}
-(void)createUI{
    
    //    用户信息顶部图片
    _uInfoView = [[UIImageView alloc]initWithFrame:CGRectMake( 10, 75, SCREEN_WIDTH - 20, SCREEN_HEIGHT/4)];
    _uInfoView.image = [UIImage imageNamed:@"dianbiao"];
    [self.view addSubview:_uInfoView];
    
    
    _cbrLab = [[UILabel alloc]initWithFrame:CGRectMake(10, 85 + SCREEN_HEIGHT/4 , (SCREEN_WIDTH - 20)/2, 40)];
    //    _cbrLab.backgroundColor = [UIColor redColor];
    //    _cbrLab.textColor  = [UIColor whiteColor];
    //    _cbrLab.font = [UIFont systemFontOfSize:16];
    _cbrLab.text = [NSString stringWithFormat:@"抄表人:%@",[GCMUserInfo instance].realName];
    _cbrLab.textColor = [UIColor colorWithRed:0.02 green:0.45 blue:0.82 alpha:1.0];
    //    _cbrLab.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:_cbrLab];
    
    NSString *str  = [NSString stringWithFormat:@"%@",[NSDate date]];
    NSArray *arrayCurrentTime = [str componentsSeparatedByString:@" "];
//    _timestr = [NSString stringWithFormat:@"%@ %@",arrayCurrentTime[0],arrayCurrentTime[1]];
//    NSLog(@"%@",arrayCurrentTime);
    _timeLab = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2, 85 + SCREEN_HEIGHT/4 , (SCREEN_WIDTH - 20)/2, 40)];
    //    _timeLab.backgroundColor = [UIColor blueColor];
    //    _timeLab.textColor  = [UIColor whiteColor];
    _timeLab.font = [UIFont systemFontOfSize:16];
    _timeLab.text = arrayCurrentTime[0];
    _timeLab.textAlignment = NSTextAlignmentRight;
    [self.view addSubview:_timeLab];
    
}


-(void)createTableView{
    
    _tableV = [[UITableView alloc]initWithFrame:CGRectMake(0, 125 + SCREEN_HEIGHT/4, SCREEN_WIDTH, SCREEN_HEIGHT  - SCREEN_HEIGHT/4 - 125)];
    _tableV.backgroundColor  = [UIColor whiteColor];
    _tableV.delegate = self;
    _tableV.dataSource =self;
    _tableV.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1.0];
    [self.view addSubview:_tableV];
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    GCMCBTJTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[GCMCBTJTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    [cell setBackgroundColor:[UIColor whiteColor]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSDictionary *dic = _dataSource[indexPath.row];
//    NSLog(@"aaaa%@",dic);
    [cell setDic:dic];
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSource.count;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 170;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    GCMChaoBiaoViewController *cb  = [[GCMChaoBiaoViewController alloc]init];
//    NSLog(@"%@",_dataSource);
    cb.a_id = [_dataSource[indexPath.row] valueForKey:@"a_id"];
    cb.t_date = [_dataSource[indexPath.row] valueForKey:@"t_date"];
    [self.navigationController pushViewController:cb animated:YES];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
    backItem.title = @"抄表录数";
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationItem.backBarButtonItem = backItem;
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
